package com.swu.controller;

import com.swu.service.MedicalRecordService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import java.util.Map;

@Tag(name = "病案首页视图", description = "病案首页页面相关接口")
@Controller
@RequestMapping("/medical-record")
@RequiredArgsConstructor
public class MedicalRecordViewController {

    private final MedicalRecordService medicalRecordService;

    @Operation(summary = "查看病案首页", description = "根据病案号查看病案首页详情")
    @GetMapping("/detail")
    public ModelAndView viewMedicalRecordDetail(
            @Parameter(description = "病案号(精确匹配)", required = true)
            @RequestParam String medicalRecordId) {
        // 获取病案首页数据
        Map<String, Object> data = medicalRecordService.getMedicalRecordDetailHtml(medicalRecordId);
        
        // 创建ModelAndView对象，指定视图名称
        ModelAndView mav = new ModelAndView("medical_record_detail");
        // 添加所有数据到模型中
        mav.addAllObjects(data);
        
        return mav;
    }
} 